cd load_data_2_Matlab

### Read mappings from canton to more aggregate geographic levels
mkdir -p ../data/data_mat/timeLocationAggregations/location/CantonId

for AGG_GEO_LEVEL in DEP RegionId oldRegionId; do
	INPUT_FILE=../data/data_csv/timeLocationAggregations/location/CantonId/${AGG_GEO_LEVEL}.csv
	OUTPUT_FILE=../data/data_mat/timeLocationAggregations/location/CantonId/${AGG_GEO_LEVEL}.mat
    execMatlab "importAggregationFE('$INPUT_FILE', '$OUTPUT_FILE', {'char', 'char'}); quit();"
done

### Read mappings from day/week to more aggregate time levels
for TIME_LEVEL in day week; do
    mkdir -p ../data/data_mat/timeLocationAggregations/time/${TIME_LEVEL}
    for AGG_TIME_LEVEL in week month quarter dayOfWeek; do
        if [ $TIME_LEVEL == $AGG_TIME_LEVEL ]; then continue; fi
        if [ $TIME_LEVEL != "day" ]    && [ $AGG_TIME_LEVEL == 'dayOfWeek' ]; then continue; fi
        if [ $TIME_LEVEL == "day" ]; then TIME_ID=dayNum; fi
        if [ $TIME_LEVEL == "week" ]; then TIME_ID=weekNum; fi
        if [ $AGG_TIME_LEVEL == "day" ]; then AGG_TIME_ID=dayNum; fi
        if [ $AGG_TIME_LEVEL == "week" ]; then AGG_TIME_ID=weekNum; fi
        if [ $AGG_TIME_LEVEL == "quarter" ]; then AGG_TIME_ID=quarter; fi
        if [ $AGG_TIME_LEVEL == "dayOfWeek" ]; then AGG_TIME_ID=dayOfWeek; fi
	    INPUT_FILE=../data/data_csv/timeLocationAggregations/time/$TIME_LEVEL/${AGG_TIME_LEVEL}.csv
	    OUTPUT_FILE=../data/data_mat/timeLocationAggregations/time/$TIME_LEVEL/${AGG_TIME_LEVEL}.mat
        execMatlab "importAggregationFE('$INPUT_FILE', '$OUTPUT_FILE', {'double', 'double'}); quit();"
    done
done

### Read / make spatial matrices: (origin,destination)-variables
mkdir -p ../data/data_mat/SpatialWeights

# Contiguity
execMatlab "importContiguityMatrix2Matlab('../data/data_csv/SpatialMatrices/Contiguity.csv', '../data/data_mat/SpatialWeights', 'Weight_Contiguity'); quit();"

# sameDEP
execMatlab "makeSpatialMatrix_sameGeoAggEntity('../data/data_mat/timeLocationAggregations/location/CantonId', '../data/data_mat/SpatialWeights'); quit();"

# GeoDistance
matlabExec "calcDistanceMatrix('../data/data_csv/centroids.csv', '../data/data_mat/SpatialWeights/GeoDistance.mat', 'haversine'); quit();"

# Professional mobility
execMatlab "importCommutingMatrix2Matlab('../data/data_csv/SpatialMatrices/MobilitePro.csv', '../data/data_csv/timeLocationAggregations/location/CantonId/DEP.csv', '../data/data_mat/SpatialWeights'); quit();"

# Tourist trips
execMatlab "importTouristTripsMatrix2Matlab('../data/data_csv/SpatialMatrices/TouristFlowsAcrossRegions.csv', '../data/data_csv/SpatialMatrices/PopulationPerCanton.csv', '../data/data_csv/SpatialMatrices/TouristBedsPerCanton.csv', \
    '../data/data_mat/SpatialWeights'); quit();"


### Read platform data
mkdir -p ../data/data_mat/platformData
execMatlab "readEvaluations('../data/data_csv/platformData', '../data/data_mat/platformData'); readEvaluations('../data/data_csv/platformData', '../data/data_mat/platformData', true); quit();"
execMatlab "readProviderMovements('../data/data_csv/platformData', '../data/data_mat/platformData'); quit();"


### Read covariates from other data sources
mkdir -p ../data/data_mat/covariates
execMatlab "importLocationData2Matlab('CantonId'); quit();"
execMatlab "importTimeData2Matlab('day'); importTimeData2Matlab('week'); quit();"
execMatlab "importLocationTimeData2Matlab('CantonId', 'day'); importLocationTimeData2Matlab('CantonId', 'week'); quit();"
execMatlab "combineCovariates('CantonId', 'day'); combineCovariates('CantonId', 'week'); quit();"

cd ..
